home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / PEARSN.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  878b  |  37 lines

  1. PROCEDURE pearsn(x,y: nparray; n: integer; VAR r,prob,z: real);
  2. (* Programs using routine PEARSN must define type
  3. TYPE
  4.    nparray = ARRAY [1..n] OF real;
  5. in the main routine. *)
  6. CONST
  7.    tiny=1.0e-20;
  8. VAR
  9.    j: integer;
  10.    yt,xt,t,syy,sxy,sxx,df,ay,ax: real;
  11. BEGIN
  12.    ax := 0.0;
  13.    ay := 0.0;
  14.    FOR j := 1 TO n DO BEGIN
  15.       ax := ax+x[j];
  16.       ay := ay+y[j]
  17.    END;
  18.    ax := ax/n;
  19.    ay := ay/n;
  20.    sxx := 0.0;
  21.    syy := 0.0;
  22.    sxy := 0.0;
  23.    FOR j := 1 TO n DO BEGIN
  24.       xt := x[j]-ax;
  25.       yt := y[j]-ay;
  26.       sxx := sxx+sqr(xt);
  27.       syy := syy+sqr(yt);
  28.       sxy := sxy+xt*yt;
  29.    END;
  30.    r := sxy/sqrt(sxx*syy);
  31.    z := 0.5*ln(((1.0+r)+tiny)/((1.0-r)+tiny));
  32.    df := n-2;
  33.    t := r*sqrt(df/(((1.0-r)+tiny)*((1.0+r)+tiny)));
  34.    prob := betai(0.5*df,0.5,df/(df+sqr(t)))
  35. (*   prob := erfcc(abs(z*sqrt(n-1.0))/1.4142136)   *)
  36. END;
  37.